package org.jash.bindingtest

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable

class Cart:BaseObservable() {
    val price = 1200f
    var num = 2
        set(value) {
            field = value
            notifyPropertyChanged(BR.numString)
            notifyPropertyChanged(BR.total)
        }
    @get:Bindable
    @set:Bindable
    var numString:String
        get() = num.toString()
        set(value) {
            num = try { value.toInt() } catch (e:Exception) { 0 }
        }
    @get:Bindable
    val total
        get() = if (check) price * num else 0f
    fun changeNum(n:Int) {
        num += n
    }
    var check:Boolean = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.total)
        }
}